﻿
create PROCEDURE [dbo].[proc_ysh_SearchCusName]
(
   @CusId uniqueidentifier,
   @CusName nvarchar(200),
   @companyId int,
   @SalesPerson varchar(20),
   @ServicePerson varchar(20)
)
AS
BEGIN
	Declare @tmpCusId varchar(100)
	Select @tmpCusId=CustomerId From Customer Where CompanyId=@companyId And CustomerName=@CusName
	If @tmpCusId is Null
		Begin
			Insert Into Customer(CompanyId,CustomerId,CustomerName,StateId,ProtectId,CreateName,CreateDate,SalesPerson,ServicePerson,audit) Values
				(@CompanyId,@CusId,@CusName,2,3,'','2006-01-01',@SalesPerson,@ServicePerson,1)
			Select @CusId As CustomerId
		End
	Else
		Select @tmpCusId As CustomerId
END